package com.platform.admin.enums;

import com.platform.admin.contant.BusinessConstant;
import lombok.AllArgsConstructor;
import lombok.Getter;

import javax.validation.groups.Default;
import java.util.*;

/**
 * @Description: mes_machining_category_attribute 工艺属性
 * @author: yuanlai
 * @CreateTime: 2022/5/11 19:45
 */
@Getter
@AllArgsConstructor
public enum AttributeTypeEnum {

    CUT(0, "订料", false, false, 0, Default.class),
    PRINTING(1, "印刷", false, false, 1, Default.class),
    //COATING(2, "覆膜", false, true, 2, OneGroup.class),
    OIL(3, "过油", false, false, 2, Default.class),
    //BEI(4, "模切", false, true, 1, TwoGroup.class),
    STICKY(5, "粘盒", true, true, 1, Default.class),
    GILDING(6, "烫金", false, true, 1, Default.class),
    //    CONVEX(7, "击凸", false, true, 1, TwoGroup.class),
//    DE_BOSS(8, "击凹", false, true, 1, TwoGroup.class),
//    LOCAL_UV(9, "局部UV", false, true, 1, ScreenPrintingGroup.class),
    WINDOW(10, "贴窗", true, true, 1, Default.class),
    FRAMED(11, "对裱卡纸", false, false, 2, Default.class),
    EMBOSSING(12, "压纹", false, false, 2, Default.class),
    FRAMED_PIT(28, "对裱坑纸", false, false, 2, Default.class),
    HEMMING(29, "折边", false, false, 1, Default.class),
    FORMING(31, "成型", false, false, 1, Default.class),
    FOLDING(32, "折页", false, false, 1, Default.class),
    BINDING(34, "装钉", false, false, 1, Default.class),
    GLUE(36, "贴合", false, false, 1, Default.class),
    VELVET(37, "裱绒", false, false, 1, Default.class),
    BOTTOM_ADHESIVE(38, "底部背胶", false, false, 1, Default.class),
    LACING(39, "穿绳", false, false, 1, Default.class),
    hit_corns(40, "打鸡眼", false, false, 1, Default.class),
    STICK_MAGNET(41, "贴磁铁", true, false, 1, Default.class),
    TWO_ADHESIVE(43, "粘双面胶", true, false, 1, Default.class),
    //    SILK_SCREEN_MONOCHROME(45, "丝印单色", false, true, 1, ScreenPrintingGroup.class),
//    SILK_SCREEN_BEADS(46, "丝印滴珠", false, true, 1, ScreenPrintingGroup.class),
//    SILK_SCREEN_MATTE(47, "丝印磨砂", false, true, 1, ScreenPrintingGroup.class),
    REMOVE_WASTE(48, "除废", false, true, 0, Default.class),
    CTP(49, "CTP制版", false, false, 1, Default.class),
    REFRACTION(50, "折光", false, false, 2, Default.class),
    BOILING_HOT(51, "滚烫", false, false, 1, Default.class),
    LOCALUV_SEVEN(52, "局部七彩UV", false, false, 1, Default.class),
    FOAM(53, "发泡", false, false, 1, Default.class),
    DEEP_EMBOSSING(54, "深压纹", false, false, 1, Default.class),
    BIG_VERSION_LAMINATE(55, "大版裱纸", false, false, 2, Default.class),
    LASER_ENGRAVING(56, "激光雕刻", true, false, 1, Default.class),
    V_GROOVE(57, "V槽", true, false, 1, Default.class),
    PART_LAMINATE(58, "零件裱纸", true, false, 0, Default.class),
    STITCHING(59, "车线", true, false, 1, Default.class),
    COMPUTERIZED_EMBROIDERY(60, "电脑绣花", true, false, 1, Default.class),
    SPONGE_LAMINATION(61, "海绵裱合", true, false, 1, Default.class),
    HARDCOVER_PRODUCTION_LINE(62, "精装盒生产线", true, false, 0, Default.class),
    ADVANCE_FOLD(63, "预折", true, false, 1, Default.class),
    //    SCREEN_PRINTING(64, "丝印", false, true, 1, ScreenPrintingGroup.class),
    CUSTOMIZE_BIG_VERSION(65, "大版自定义", false, false, 1, Default.class),
    CUSTOMIZE_PO(66, "PO自定义", true, false, 1, Default.class),
    PACKAGING(67, "打包", true, true, 0, Default.class);

    /**
     * 所有模切相关的工序
     **/
//    public static List<Integer> BEI_LIST = Arrays.asList(AttributeTypeEnum.BEI.getAttId(), AttributeTypeEnum.CONVEX.getAttId(), AttributeTypeEnum.DE_BOSS.getAttId());
    /**
     * 所有丝印相关工序
     */
//    public static List<Integer> SCREEN_PRINTING_LIST = Arrays.asList(AttributeTypeEnum.LOCAL_UV.getAttId(), AttributeTypeEnum.SILK_SCREEN_MONOCHROME.getAttId(),
//            AttributeTypeEnum.SILK_SCREEN_BEADS.getAttId(), AttributeTypeEnum.SILK_SCREEN_MATTE.getAttId());
//    public static List<AttributeTypeEnum> MERGE_ATTRIBUTE = Arrays.asList(CONVEX, DE_BOSS);
    /**
     * 所有上线看板并不需要排产的工序：目前：除废，PDA，粘盒
     **/
    public static List<Integer> NO_SCHEDULED_ATT_ID_LIST = Arrays.asList(REMOVE_WASTE.getAttId(), PACKAGING.getAttId(), STICKY.getAttId());
    private final Integer attId;
    private final String name;
    /**
     * 是否 PO维度
     **/
    private final boolean isPo;
    /**
     * 是否上线机长看板
     **/
    private final boolean isOnline;
    /**
     * 质检分组 0:不质检 1:按PO质检 2:按大版质检
     **/
    private final int qualityGroup;

    //TODO 待补充
    /**
     * 校验组
     **/
    private final Class<? extends Default> validGroupClass;

    public static String getNameByAttId(int attId) {
        for (AttributeTypeEnum typeEnum : values()) {
            if (typeEnum.getAttId() == attId) {
                return typeEnum.getName();
            }
        }
        return "";
    }

    public static AttributeTypeEnum getEnumByAttId(int attId) {
        for (AttributeTypeEnum typeEnum : values()) {
            if (typeEnum.getAttId() == attId) {
                return typeEnum;
            }
        }
        return null;
    }

    /**
     * 根据工艺id获取校验组
     **/
    public static Class<? extends Default> getValidGroupClassByAttId(int attId) {
        for (AttributeTypeEnum typeEnum : values()) {
            if (typeEnum.getAttId() == attId) {
                return typeEnum.getValidGroupClass();
            }
        }
        return Default.class;
    }


    /**
     * 如果是“模切” 工序需要添加，击凸和击凹工序
     *
     * @param attId 预计起飞时间
     * @return {@link List}<{@link Integer}>
     */
    public static List<Integer> switchType(Integer attId) {
        if (Objects.isNull(attId)) {
            return null;
        }
//        if (AttributeTypeEnum.BEI.getAttId().equals(attId)) {
//            return BEI_LIST;
//        }
//        if (AttributeTypeEnum.SCREEN_PRINTING.getAttId().equals(attId)) {
//            return SCREEN_PRINTING_LIST;
//        }
        return Collections.singletonList(attId);
    }

    /**
     * 获取大板维度的工序
     *
     * @return
     */
    public static List<Integer> getGroupAttributeId() {
        List<Integer> typeList = new ArrayList<>();
        for (AttributeTypeEnum typeEnum : values()) {
            if (Boolean.FALSE.equals(typeEnum.isPo)) {
                typeList.add(typeEnum.attId);
            }
        }
        return typeList;
    }

    public static Map<Integer, String> getGroupAttributeMap() {
        Map<Integer, String> typeMap = new HashMap<>();
        for (AttributeTypeEnum typeEnum : values()) {
            if (Boolean.FALSE.equals(typeEnum.isPo)) {
                typeMap.put(typeEnum.attId, typeEnum.name);
            }
        }
        return typeMap;
    }

    public static Map<Integer, String> getPoAttributeMap() {
        Map<Integer, String> typeMap = new HashMap<>();
        for (AttributeTypeEnum typeEnum : values()) {
            if (Boolean.TRUE.equals(typeEnum.isPo)) {
                typeMap.put(typeEnum.attId, typeEnum.name);
            }
        }
        return typeMap;
    }

    public static Map<Integer, String> getQualityMap() {
        Map<Integer, String> typeMap = new HashMap<>();
        for (AttributeTypeEnum typeEnum : values()) {
            if (typeEnum.qualityGroup > BusinessConstant.NUM_ZERO) {
                typeMap.put(typeEnum.attId, typeEnum.name);
            }
        }
        return typeMap;
    }

    public static List<Integer> getPoAttributeId() {
        List<Integer> typeList = new ArrayList<>();
        for (AttributeTypeEnum typeEnum : values()) {
            if (Boolean.TRUE.equals(typeEnum.isPo)) {
                typeList.add(typeEnum.attId);
            }
        }
        return typeList;
    }

    public static List<Integer> getPoAttributeIdWithOutPack() {
        List<Integer> typeList = new ArrayList<>();
        for (AttributeTypeEnum typeEnum : values()) {
            if (Boolean.TRUE.equals(typeEnum.isPo) && !Objects.equals(typeEnum.attId, PACKAGING.getAttId())) {
                typeList.add(typeEnum.attId);
            }
        }
        return typeList;
    }


    /**
     * 获取所有的工序id
     *
     * @return {@link List}<{@link Integer}>
     */
    public static List<Integer> getAllAttributeId() {
        List<Integer> typeList = new ArrayList<>();
        for (AttributeTypeEnum typeEnum : values()) {
            typeList.add(typeEnum.attId);
        }
        return typeList;
    }


    /**
     * 获取已经接入的工序id
     *
     * @return {@link List}<{@link Integer}>
     */
    public static List<Integer> getProcessAlready() {
        List<Integer> processAlreadyList = new ArrayList<>();
        for (AttributeTypeEnum typeEnum : values()) {
            if (Boolean.TRUE.equals(typeEnum.isOnline)) {
                processAlreadyList.add(typeEnum.attId);
            }
        }
        return processAlreadyList;
    }

    /**
     * 获取可以排产的工序id
     *
     * @return {@link List}<{@link Integer}>
     */
    public static List<Integer> getNeedScheduled() {
        List<Integer> processAlreadyList = new ArrayList<>();
        for (AttributeTypeEnum typeEnum : values()) {
            if (Boolean.TRUE.equals(typeEnum.isOnline) && !Objects.equals(typeEnum, REMOVE_WASTE)) {
                processAlreadyList.add(typeEnum.attId);
            }
        }
        return processAlreadyList;
    }

    /**
     * 获取可以排产的工序id
     *
     * @return {@link List}<{@link Integer}>
     */
    public static List<Integer> getNeedQuality() {
        List<Integer> needQualityList = new ArrayList<>();
        for (AttributeTypeEnum typeEnum : values()) {
            if (typeEnum.qualityGroup > BusinessConstant.NUM_ZERO) {
                needQualityList.add(typeEnum.attId);
            }
        }
        return needQualityList;
    }


    /**
     * 判断是否大板维度的工序
     *
     * @param attributeId 属性id
     * @return boolean
     */
    public static boolean isGroupAttribute(Integer attributeId) {
        return getGroupAttributeId().contains(attributeId);
    }


    /**
     * 判断是否po维度的工序
     *
     * @param attributeId 属性id
     * @return boolean
     */
    public static boolean isPoAttribute(Integer attributeId) {
        return getPoAttributeId().contains(attributeId);
    }


    /**
     * 是否上线上线看板并需要排产，目前除废没有排产逻辑
     *
     * @param attributeId 属性id
     * @return boolean
     */
    public static boolean needScheduled(Integer attributeId) {
        return getProcessAlready().contains(attributeId) && !NO_SCHEDULED_ATT_ID_LIST.contains(attributeId);
    }

    /**
     * 工艺（已上线看板）是否不需要排产：true表示不需要排产
     *
     * @param attributeId 属性id
     * @return boolean
     */
    public static boolean unnecessaryScheduled(Integer attributeId) {
        return NO_SCHEDULED_ATT_ID_LIST.contains(attributeId);
    }

}
